package com.wangtao.firstapp.adapters;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.wangtao.firstapp.R;
import com.wangtao.firstapp.modles.OriginalAuthorPublish;

/**
 * 用户作者  介绍页面（发布—>晒单，文章） 晒单的适配器
 * Created by lanouhn on 16/9/8.
 */
public class AuthorPublishOneAdapter extends BaseAdapter {

    private Context context;
    private OriginalAuthorPublish originalAuthorPublish;

    public AuthorPublishOneAdapter(Context context, OriginalAuthorPublish originalAuthorPublish) {
        this.context = context;
        this.originalAuthorPublish = originalAuthorPublish;
    }

    @Override
    public int getCount() {
        return (originalAuthorPublish.getData().getPost().size());
    }

    @Override
    public Object getItem(int position) {
        return originalAuthorPublish.getData().getPost().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public class ViewHolder{
        private ImageView imageview;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView = View.inflate(context, R.layout.item_mygridview4, null);
            holder = new ViewHolder();
            holder.imageview= (ImageView) convertView.findViewById(R.id.iv_item_mygridview4);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        Picasso.with(context).load(originalAuthorPublish.getData().getPost().get(position).getMini_pic_url()).into(holder.imageview);

        holder.imageview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent=new Intent();
                context.startActivity(intent);
            }
        });


        return convertView;
    }
}
